package myself.a010BinaryTreeRecursion;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 叶之越
 * Description 最大快乐值问题
 * Date 2021/1/28
 * Time 22:04
 * Mail 739153436@qq.com
 */
public class MaxHappy {
    public static int maxHappy2(Employee head) {
        Info allInfo = process(head);
        return Math.max(allInfo.no, allInfo.yes);
    }

    public static Info process(Employee random) {
        if (random == null) {
            return new Info(0, 0);
        }
        int no = 0;
        int yes = random.happy;
        for (Employee next : random.nexts) {
            Info n = process(next);
            no += Math.max(n.no, n.yes);
            yes += n.no;
        }
        return new Info(no, yes);
    }

    public static class Employee {
        public int happy;
        public List<Employee> nexts;

        public Employee(int h) {
            happy = h;
            nexts = new ArrayList<>();
        }

    }

    public static class Info {
        public int no;
        public int yes;

        public Info(int n, int y) {
            no = n;
            yes = y;
        }
    }
}
